if(!dojo._hasResource["opm.widgets.GenericBrowserFields"]){
dojo._hasResource["opm.widgets.GenericBrowserFields"] = true;
dojo.provide("opm.widgets.GenericBrowserFields");
dojo.require("dijit._Widget");
dojo.declare("opm.widgets.GenericBrowserFields",dijit._Widget,
{
   ajaxCallUrl: "", 
   ajaxCallType: "",

   widgetId:"",
   contentId:"",

   dataSource: null,
   constructor:function(args){
      this.contentId = args.contentId;
      this.widgetId = args.id;
      this.dataSource = args.dataSource;
   },

    show:function(){
      var htmlData = this._parseTable();
      console.log('ContentId: ' + this.contentId + " ---- WidgetId: " + this.widgetId);
      dojo.html.set(dojo.byId(this.contentId), htmlData, {parseContent: true});
      this.initEvents();
   },

   connectEvent:function(eventName, callBackFunction){
      if (eventName == 'rowDbClick'){
         this._rowDbClick = callBackFunction;
      }
   },

   initEvents:function(){
      var localWidget = this;
      dojo.query('table#tableWidgetBrowserField tbody tr').connect('ondblclick', function(evt){
         localWidget._rowDbClick(dojo.query('input[type="hidden"]', this)[0].value);
      });
   },

   setDataBrowser:function(data){
      this.dataSource = data;
   },

   createBrowser:function(){
      var common = this;
      var args = {
         ajaxUrl: this.ajaxCallUrl,
         callback: function (data){
             common.setDataBrowser(data);
             common.show();
      }};
      OPM.callAjaxWidget(args, this.contentId, this.ajaxCallType);
    },

   _parseTable:function(){
      var tableHtml = '<table id="tableWidgetBrowserField" style="width: 100%;" class="table">';
      tableHtml += this._parseHeader();
      tableHtml += this._parseRows();
      tableHtml += '</table>';
      return tableHtml;
   },

   _parseHeader:function(){
      var browserCols = this.dataSource.browserfields.cols;
      var workflowItemDef = this.dataSource.workflowItemDef.properties;
      var theadHtml = '<thead><tr>';
      for (var index=0; index<browserCols.length; index++){
         var colName = browserCols[index];
         var property = workflowItemDef[colName];
         theadHtml += '<th>' + property.name + '</th>';
      }
      theadHtml += '</tr></thead>';
      return theadHtml;
   },

   _parseRows:function(){
      var browserCols = this.dataSource.browserfields.cols;
      var workflowItemsData = this.dataSource.workflowItemDef.data;
      var tRowHtml = '<tbody>';
      for (var index=0; index<workflowItemsData.length; index++){
         tRowHtml += '<tr>';
         var workflowItemData = workflowItemsData[index];
         for (var indexCol=0; indexCol<browserCols.length; indexCol++){
            var colName = browserCols[indexCol];
            if (colName=='p_workintanceid'){
               tRowHtml += '<td><input type="hidden" value="auth/workflowItem/'+workflowItemData[colName]+'"/>' + workflowItemData[colName] + '</td>';
            }else {
               tRowHtml += '<td>'+ workflowItemData[colName] + '</td>';
            }
         }
         tRowHtml += '</tr>';
      }
      tRowHtml += '</tbody>';
      return tRowHtml;
   },

   _rowDbClick:function(){}
}
);}